const momentService = require('../service/moment.service');

class MomentController {
  async publishMoment(ctx, next) {
    const {content} = ctx.request.body;
    const {id} = ctx.user;

    const result = await momentService.create(content, id);

    ctx.body = result;
    
  }

  async getMoment(ctx, next) {
    const {momentId} = ctx.params;

    const result = await momentService.getMoment(momentId);
    
    ctx.body = result;
  }

  async getMoments(ctx, next) {
    const {offset, size} = ctx.query;

    const result = await momentService.getMoments(offset, size);
    
    ctx.body = result;
  }
  
  async changeMoment(ctx, next) {
    const {momentId} = ctx.params;
    const {content} = ctx.request.body;

    await momentService.changeMoment(momentId, content);
    
    ctx.body = '修改评论成功！';
  }

  async removeMoment(ctx, next) {
    const {momentId} = ctx.params;
    
    await momentService.removeMoment(momentId);
    
    ctx.body = '删除评论成功！';
  }
}

module.exports = new MomentController();